//
//  NetTool.swift
//  TinyShopKeeper
//
//  Created by rimi on 16/5/27.
//  Copyright © 2016年 yuying. All rights reserved.
//

import UIKit
import Alamofire

class NetTool: NSObject {
 
    //MARK:-- 封装一个类方法,request,参数如下
    //loadingMassage参数类型String~~~~给用户显示的信息
    //urlString参数类型String~~~~~接口地址
    //paramDictionary参数类型[String:AnyObject]~~~~接口需要的数据
    //successAction:(responseObject:AnyObject)->Void是个闭包就是个函数参数,errorAction:(error:NSError)->Void也是~~~successAction:请求成功的获得的数据  errorAction:错误执行方法
    class func requestX(loadingMassage:String,urlString:String,paramDictionary:[String:AnyObject],successAction:(responseObject:AnyObject)->Void,errorAction:(error:NSError)->Void) {
        
        //提示用户
        MBProgressHUD .showMessage(loadingMassage)
        
        request(Method.POST, baseURLAppend(urlString), parameters: paramDictionary, encoding: ParameterEncoding.JSON, headers: nil).responseJSON { (response) -> Void in
            
            
            switch response.result{
                
            case.Success(let value):
                successAction(responseObject: value)
                
            case.Failure(let error):
                errorAction(error: error)
                
            }
        }
    }
}
